<template>
    <div class="icons">
        <swiper ref="mySwiper" :options="swiperOption">
            <swiper-slide v-for="(page,i) in pages" :key="i">
                <div class="icon" v-for="item in page" :key="item.id">
                    <div class="icon-img">
                        <img :src="item.imgUrl" alt="">
                    </div>
                    <p>{{item.desc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>

<script>
    export default {
        props:{
            iconList:Array
        },
        data(){
            return {
                swiperOption: {
                    loop: false
                }
            }
        },
        computed: {
            // 计算icon的数量，大于8个自动跳到第2页
            pages(){
                const pages=[]
                this.iconList.forEach((item,index)=>{
                    let page=Math.floor(index/8)
                    if(!pages[page]){
                        pages[page]=[]
                    }
                    pages[page].push(item)
                })
                return pages
            }
        },
    }
</script>

<style lang="stylus" scoped>
@import '~@/assets/css/global.styl'
@import '~@/assets/css/minis.styl'
    // 处理在swiper不能滑动问题
    .icons >>> .swiper-container
        height 0
        padding-bottom 50%
    .icons
        margin-top .1rem
        .icon
            position relative
            float left
            width 25%
            height 0
            padding-bottom 25%
            overflow hidden
            .icon-img
                position absolute
                top 0
                left 0
                right 0
                bottom .44rem
                box-sizing border-box
                padding .1rem
                img
                    display block
                    height 100%
                    margin auto
            p
                position absolute
                left 0
                right 0
                bottom 0
                height .44rem
                line-height .44rem
                color $darkTextColor
                text-align center
                ellipsis()

</style>